<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<script type="text/javascript" src="/plugins/jquery.min.js"></script>
<script type="text/javascript" src="/js/buildingSelect.js?v=1"></script>
<script type="text/javascript" src="/js/modules/card.min.js"></script>
<script type="text/javascript" src="/js/core/utils.js"></script>
<script type="text/javascript" src="/pages/business/card/addCard-min.js?version=5"></script>
<jsp:include page="/share/top.jsp"/>
<link rel="stylesheet" href="/plugins/adminLte/css/AdminLTE.min.css">
<div class="box box-primary">
    <div class="box-frame">
        <form action="/card/save.x" method="post" id="cardSubmit">
            <input type="hidden" id="cardType" name="cardType"/>
            <input type="hidden" id="commCode" name="commCode"/>
            <OBJECT id=USBCardRW classid="CLSID:C720F392-B44D-457C-A633-15ED97D0FEA3"
                    codebase="/Resource/JHCardActiveX.ocx" width="0" height="0"></OBJECT>
            <div class="layui-tab layui-tab-brief" lay-filter="tab-push">
                <ul class="layui-tab-title">
                    <li class="layui-this">新增普通卡</li>
                    <li>新增超级卡</li>
                </ul>
                <div class="layui-tab-content" style="padding:0px;margin-top:5px;">
                    <div class="layui-tab-item layui-show">
                        <div class="tablecontent2">
                            <table class="layui-table" cellpadding="0" bordercolor="#dbdbdb" cellspacing="0" border='1'>
                                <tbody>
                                <tr>
                                    <td class="t0">门禁卡编号：</td>
                                    <td class="t1">
                                        <input id="nCardNo" name="nCardNo" maxlength="20"/>
                                        <button type="button" class="layui-btn layui-btn-mini layui-btn-normal"
                                                onclick="readNo();">读取卡号
                                        </button>
                                        <button type="button" class="layui-btn layui-btn-mini layui-btn-danger"
                                                onclick="resumeNormalCard();">恢复白卡
                                        </button>
                                    </td>
                                </tr>

                                <tr>
                                    <td class="t0">所属业主：
                                    <td class="t1">
                                        <button type="button" class="layui-btn layui-btn-small layui-btn-normal"
                                                style="display:inline" onclick="dlgBuildingSelect('true')">选择业主
                                        </button>
                                        <div id="selectOwner" style="display:inline"></div>
                                        <input type="hidden" id="ownerCode" name="ownerCode"/>
                                        <input type="hidden" id="ownerName" name="ownerName"/>
                                        <input type="hidden" id="roomName" name="roomName"/>
                                    </td>
                                </tr>

                                <tr>
                                    <td class="t0">状态：</td>
                                    <td class="t1">
                                        <select id="nState" name="nState">
                                            <option value="">请选择卡状态</option>
                                            <option value="01" selected>在用</option>
                                            <option value="02">停用</option>
                                        </select>
                                        <span style="color: red;"><strong>*</strong></span>
                                    </td>
                                </tr>

                                <tr>
                                    <td class="t0">开始时间：</td>
                                    <td class="t1">
                                        <input type="text" name="beginDate"
                                               styleClass="Wdate" onfocus="WdatePicker({dateFmt:'yyyyMMdd'});"/>(格式如：20140118)
                                    </td>
                                </tr>
                                <tr>
                                    <td class="t0">结束时间：</td>
                                    <td class="t1">
                                        <input type="text" name="endDate"
                                               styleClass="Wdate" onfocus="WdatePicker({dateFmt:'yyyyMMdd'});"/>(格式如：20140118)
                                    </td>
                                </tr>
                                <tr>
                                    <td class="t0">门禁权限：
                                        <button type="button" class="layui-btn layui-btn-small" onclick="dlgAddPerms()">
                                            <i class="layui-icon"
                                               style="font-size: 33px; color: #fbfbfb;vertical-align: middle">&#xe608;</i>&nbsp添加
                                        </button>
                                    </td>
                                    <td id="perms" class="t1">

                                    </td>
                                </tr>

                                </tbody>
                            </table>
                            <input type="button" value="保存" class="layui-btn layui-btn-small layui-btn-normal"
                                   onclick="publishNormalCard()">
                            <input type="button" value="取消" class="layui-btn layui-btn-small"
                                   onclick="history.back(-1);">
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="tablecontent2">
                            <table class="layui-table" cellpadding="0" bordercolor="#dbdbdb"
                                   cellspacing="0" border='1'>
                                <thead>
                                <tr>
                                    <th colspan="2" class="th0"></th>
                                </tr>
                                </thead>
                                <tr>
                                    <td class="t0">门禁卡编号：</td>
                                    <td class="t1">
                                        <input id="sCardNo" name="sCardNo" maxlength="20"/>
                                        <button type="button" class="layui-btn layui-btn-mini layui-btn-normal"
                                                onclick="readSupperNo();">读取卡号
                                        </button>
                                        <button type="button" class="layui-btn layui-btn-mini layui-btn-danger"
                                                onclick="resumeSupperCard();">恢复白卡
                                        </button>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="t0">小区：</td>
                                    <td id="commTd" class="t1">
                                        <c:if test="${!empty commDimList}">
                                        <select name="sCommCode">
                                            <option value="">--请选择--</option>
                                            <c:forEach var="comm" items="${commDimList}">
                                                <option value='${comm.commCode }'
                                                        <c:if test="${comm.commCode== TblOwnerDimForm.commCode}"> selected="selected"</c:if>>
                                                        ${comm.commCode }-${comm.commName}
                                                </option>
                                            </c:forEach>
                                        </select>
                                        </c:if>
                                        <c:if test="${!empty commDimBo}">
                                        <select name="sCommCode" style="display:none">
                                            <option value="${commDimBo.commCode}" selected></option>
                                        </select>
                                            ${commDimBo.commName}
                                        </c:if>
                                </tr>
                                <tr>
                                    <td class="t0">状态：</td>
                                    <td class="t1">
                                        <select id="sState" name="sState">
                                            <option value="">请选择卡状态</option>
                                            <option value="01" selected>在用</option>
                                            <option value="02">停用</option>
                                        </select><span style="color: red;"><strong>*</strong></span></td>
                                </tr>
                            </table>
                            <input type="button" value="保存" class="layui-btn layui-btn-small layui-btn-normal"
                                   onclick="publishSupperCard()">
                            <input type="button" value="取消" class="layui-btn layui-btn-small"
                                   onclick="history.back(-1);">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<input id="sp" type="hidden" value="${sp}"/>
<a id="downloadBtn" target="downLoadFileFrame" hidden href="/Resource/regCardActiveX.exe"></a>
<iframe name="downLoadFileFrame" hidden></iframe>
<jsp:include page="/share/foot.jsp"/>
<script>
    layui.use(['layer', 'element'], function () {
        var layer = layui.layer;

        var commCodeStr = '${commDimBo}';

        setCommSelect("commCode");
        setAreaSelect("areaCode");
        setBuildingSelect("buildingCode");
        setUnitSelect("unitCode");
        setRoomSelect("roomId");
        setOwnerSelect("ownerCode");

        setUrl('/BuildingsCtrl/getUnitsInfo.x');
        setOwnerUrl('/owner/findOwnerByRoom.x');
        if (commCodeStr != null && commCodeStr != '') {
            getSelectData(commCodeStr);
        }

        var cardObj = document.getElementById("USBCardRW");

        cardModuleInit(layer, cardObj, "");

        if (checkBrowser() != "IE") {
            layer.alert("门禁功能目前只支持IE浏览器!", {icon: 2});
            return;
        }

        try {
            cardObj.Connected();
        }
        catch (e) {
            layer.confirm("检测到刷卡控件未加载,假如您没有安装刷卡插件,点击确定下载安装<br>假如已安装,初次运行可能要点击下方允许按钮<br><hr/>" +
                "注意事项: <br>1. 请忽略杀毒软件信息" +
                "<br>2. 请以管理员权限运行自解压安装程序,解压路径随意" +
                "<br>3. 安装完请重启浏览器", function (index) {
                console.log("download");
                document.getElementById("downloadBtn").click();
                layer.close(index);
            });
        }

        if ('${message}' != '') {
            layer.alert('${message}');
        }
    });
</script>
